import 'package:bruno/bruno.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../AppConfig/Config.dart';

class DispatchList extends StatefulWidget {
  const DispatchList({super.key});

  @override
  State<DispatchList> createState() => _DispatchListState();
}

class _DispatchListState extends State<DispatchList> {
  List dataList=[];
  int pageNum=1;
  List isChooseList=[];
  bool isShow=false;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }
// 模拟加载更多数据的方法
  void onReachBottom() {
    setState(() {
      pageNum=pageNum+1;

    });

    // 在这里可以执行加载更多数据的逻辑
  }


// 模拟加载更多数据的方法
  void _onRefresh() {
    setState(() {
      pageNum=1;

    });

    // 在这里可以执行加载更多数据的逻辑
  }

  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        backgroundColor: Colors.white,
        centerTitle: true,
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios, color: Colors.black),
          onPressed: () => Navigator.of(context).pop(),
        ),
        title: Text("调度",style: TextStyle(color: Colors.black,fontWeight: FontWeight.w300,fontSize: 16.sp),),
        actions: [
          GestureDetector(
            child: Text("全选     ",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),),
            onTap: (){
              setState(() {
                if(isChooseList.toString()==[0,1,2].toString()){
                  isChooseList=[];
                }else
                isChooseList=[0,1,2];
              });
            },
          )
        ],
      ),
      body: Container(
        margin: EdgeInsets.only(top: 10.h,left: 8.w,right: 8.w),
        child:Column(
          children: [
            Expanded(child:  EasyRefresh(
                header:
                ClassicHeader(
                  dragText: '下拉刷新',
                  armedText: '准备释放',
                  readyText: '加载中...',
                  processingText: '加载中...',
                  processedText: '刷新成功',
                  noMoreText: '暂无更多',
                  failedText: '刷新失败',
                  messageText: '刷新时间 %T',
                ),
                footer: ClassicFooter(
                  dragText: '加载更多',
                  armedText: '准备释放',
                  readyText: '加载中...',
                  processingText: '加载中...',
                  processedText: '加载成功',
                  noMoreText: '暂无更多',
                  failedText: '加载失败',
                  messageText: '加载时间 %T',
                ),
                onRefresh: _onRefresh,
                onLoad:dataList.length>pageNum*20-1?onReachBottom:null,
                child:
                Container(

                    color: Color.fromRGBO(248, 248, 248, 1),
                    child:  ListView(

                        children: [
                          Container(
                              margin: EdgeInsets.only(top: 8.h),
                              height:screenSize.height-160.h,
                              child:
                              dataList.isNotEmpty?
                              BrnAbnormalStateWidget(
                                img: Image.asset(
                                  'lib/Images/OrderList/找货暂无货源.png',
                                  scale: 3.0,
                                ),
                                content: '您的账号暂无订单',
                              ):
                              ListView.separated(
                                shrinkWrap:true,
                                itemCount: 3,
                                itemBuilder: (BuildContext context, int index) {
                                  return GestureDetector(
                                    onTap: (){
                                      setState(() {
                                        if(isChooseList.contains(index)){
                                          isChooseList.remove(index);
                                        }else
                                        isChooseList.add(index);
                                      });
                                    },
                                    child: Container(
                                      margin: EdgeInsets.only(left: 8.w,right: 8.w),
                                      padding: EdgeInsets.only(top: 10.h,right: 10.w,bottom: 10.h,left: 10.w),
                                      decoration: BoxDecoration(
                                          border: Border.all(
                                            color:isChooseList.contains(index)?MyColors.themeColor: Colors.white,
                                            width: 1,
                                          ),
                                          color:isChooseList.contains(index)?Color.fromRGBO(251, 236, 228, 1): Colors.white,
                                          borderRadius: BorderRadius.all(Radius.circular(10))),
                                      child: Column(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: [
                                          Row(
                                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                            children: [
                                              Text("YD123456",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                                              Text("苏州速搜物流科技有限公司",style: TextStyle(color: MyColors.textColor,fontSize: 11.sp),),
                                            ],
                                          ),
                                          SizedBox(height: 4.h,),
                                          Text("未指定客户",style: TextStyle(color: Colors.black,fontSize: 14.sp,fontWeight: FontWeight.w600),),
                                          SizedBox(height: 4.h,),
                                          Text("床单丨纸箱丨10吨",style: TextStyle(color: MyColors.textColor,fontSize: 13.sp),),
                                          SizedBox(height: 4.h,),
                                          Row(
                                            children: [
                                              Image.asset("lib/Images/OrderList/装icon.png",width: 13.w,height: 13.h,),
                                              SizedBox(width: 4.w,),
                                              Container(
                                                constraints: BoxConstraints(
                                                  maxWidth:screenSize.width-60.w,

                                                ),
                                                child:   Text("江苏省苏州市吴中区展业路",style: TextStyle(color: Colors.black,fontSize: 13.sp),overflow: TextOverflow.ellipsis,),
                                              ),

                                            ],
                                          ),
                                          Image.asset("lib/Images/OrderList/垂直虚线.png",width:13.w ,height:8.h,),
                                          Row(
                                            children: [
                                              Image.asset("lib/Images/OrderList/装icon.png",width: 13.w,height: 13.h,),
                                              SizedBox(width: 4.w,),
                                              Container(
                                                constraints: BoxConstraints(
                                                  maxWidth:screenSize.width-60.w,

                                                ),
                                                child:   Text("江苏省苏州市吴中区展业路",style: TextStyle(color: Colors.black,fontSize: 13.sp),overflow: TextOverflow.ellipsis,),
                                              ),

                                            ],
                                          ),
                                          Image.asset("lib/Images/OrderList/垂直虚线.png",width:13.w ,height:8.h,),
                                          Row(
                                            children: [
                                              Image.asset("lib/Images/OrderList/卸icon.png",width: 13.w,height: 13.h,),
                                              SizedBox(width: 4.w,),
                                              Container(
                                                constraints: BoxConstraints(
                                                  maxWidth:screenSize.width-60.w,

                                                ),
                                                child:   Text("江苏省苏州市吴中区展业路",style: TextStyle(color: Colors.black,fontSize: 13.sp),overflow: TextOverflow.ellipsis,),
                                              ),

                                            ],
                                          ),
                                          Image.asset("lib/Images/OrderList/垂直虚线.png",width:13.w ,height:8.h,),
                                          Row(
                                            children: [
                                              Image.asset("lib/Images/OrderList/卸icon.png",width: 13.w,height: 13.h,),
                                              SizedBox(width: 4.w,),
                                              Container(
                                                constraints: BoxConstraints(
                                                  maxWidth:screenSize.width-60.w,
                                                ),
                                                child:   Text("江苏省苏州市吴中区展业路",style: TextStyle(color: Colors.black,fontSize: 13.sp),overflow: TextOverflow.ellipsis,),
                                              ),

                                            ],
                                          ),

                                        ],
                                      ),
                                    ),
                                  );
                                },  separatorBuilder: (context, index) { //自定义分割线
                                return   Container(
                                  height: 8.h,
                                );
                              },
                              )
                          )
                        ]
                    )
                )
            ) ,),
            Container(
              padding: EdgeInsets.only(top: 10.h,bottom: 40.h),
              height:isChooseList.isEmpty?80.h:isShow==false?120.h:400.h,
              color: Colors.white,
              width: screenSize.width,
              child: Column(
                children: [
                  if(isShow)
                    Column(
                      children: [
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            GestureDetector(
                              child: Text("     清空",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp,),
                            ),
                              onTap:(){
                                setState(() {
                                  isChooseList=[];
                                  isShow=false;
                                });
                              } ,
                            ),
                            Text("撞车清单"+"("+isChooseList.length.toString()+")",style: TextStyle(color: Colors.black,fontSize: 16.sp,fontWeight: FontWeight.w600),),
                            GestureDetector(
                              child: Text("关闭     ",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp,),
                              ),
                              onTap:(){
                                setState(() {
                                  isShow=false;
                                });
                              } ,
                            ),
                          ],
                        ),
                        SizedBox(height: 8.h,),
                        Divider(height: 1.h,color: MyColors.hintColor,),
                        Container(
                          padding: EdgeInsets.only(top: 8.h),
                          height: 250.h,
                          color: MyColors.backgreyColor,
                          child:  ListView.separated(
                            shrinkWrap:true,
                            itemCount: isChooseList.length,
                            itemBuilder: (BuildContext context, int index) {
                              return Container(
                                  margin: EdgeInsets.only(left: 8.w,right: 8.w),
                                  padding: EdgeInsets.only(top: 10.h,right: 10.w,bottom: 10.h,left: 10.w),
                                  decoration: BoxDecoration(
                                      border: Border.all(
                                        color: Colors.white,
                                        width: 1,
                                      ),
                                      color:Colors.white,
                                      borderRadius: BorderRadius.all(Radius.circular(10))),
                                  child: Column(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: [
                                      Row(
                                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                        children: [
                                          Text("YD123456",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                                          Text("苏州速搜物流科技有限公司",style: TextStyle(color: MyColors.textColor,fontSize: 11.sp),),
                                        ],
                                      ),
                                      SizedBox(height: 4.h,),
                                      Text("未指定客户",style: TextStyle(color: Colors.black,fontSize: 14.sp,fontWeight: FontWeight.w600),),
                                      SizedBox(height: 4.h,),
                                      Text("床单丨纸箱丨10吨",style: TextStyle(color: MyColors.textColor,fontSize: 13.sp),),
                                      SizedBox(height: 4.h,),
                                      Row(
                                        children: [
                                          Image.asset("lib/Images/OrderList/装icon.png",width: 13.w,height: 13.h,),
                                          SizedBox(width: 4.w,),
                                          Container(
                                            constraints: BoxConstraints(
                                              maxWidth:screenSize.width-60.w,
                                            ),
                                            child:   Text("江苏省苏州市吴中区展业路",style: TextStyle(color: Colors.black,fontSize: 13.sp),overflow: TextOverflow.ellipsis,),
                                          ),
                                        ],
                                      ),
                                      Image.asset("lib/Images/OrderList/垂直虚线.png",width:13.w ,height:8.h,),
                                      Row(
                                        children: [
                                          Image.asset("lib/Images/OrderList/装icon.png",width: 13.w,height: 13.h,),
                                          SizedBox(width: 4.w,),
                                          Container(
                                            constraints: BoxConstraints(
                                              maxWidth:screenSize.width-60.w,
                                            ),
                                            child:   Text("江苏省苏州市吴中区展业路",style: TextStyle(color: Colors.black,fontSize: 13.sp),overflow: TextOverflow.ellipsis,),
                                          ),
                                        ],
                                      ),
                                      Image.asset("lib/Images/OrderList/垂直虚线.png",width:13.w ,height:8.h,),
                                      Row(
                                        children: [
                                          Image.asset("lib/Images/OrderList/卸icon.png",width: 13.w,height: 13.h,),
                                          SizedBox(width: 4.w,),
                                          Container(
                                            constraints: BoxConstraints(
                                              maxWidth:screenSize.width-60.w,
                                            ),
                                            child:   Text("江苏省苏州市吴中区展业路",style: TextStyle(color: Colors.black,fontSize: 13.sp),overflow: TextOverflow.ellipsis,),
                                          ),
                                        ],
                                      ),
                                      Image.asset("lib/Images/OrderList/垂直虚线.png",width:13.w ,height:8.h,),
                                      Row(
                                        children: [
                                          Image.asset("lib/Images/OrderList/卸icon.png",width: 13.w,height: 13.h,),
                                          SizedBox(width: 4.w,),
                                          Container(
                                            constraints: BoxConstraints(
                                              maxWidth:screenSize.width-60.w,
                                            ),
                                            child:   Text("江苏省苏州市吴中区展业路",style: TextStyle(color: Colors.black,fontSize: 13.sp),overflow: TextOverflow.ellipsis,),
                                          ),

                                        ],
                                      ),

                                    ],
                                  ),
                                );

                            },  separatorBuilder: (context, index) { //自定义分割线
                            return   Container(
                              height: 8.h,
                            );
                          },
                          ),

                        ),
                      ],
                    ),
                  if(isChooseList.isNotEmpty)
                    GestureDetector(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              SizedBox(width: 15.w,),
                              Image.asset("lib/Images/OrderList/配载选中列表icon.png",width: 15.w,height: 15.h,),
                              Badge(backgroundColor: Colors.red,label: Text(isChooseList.length.toString(),),),
                              SizedBox(width: 8.w,),
                              Text("总件数:",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                              Text("0件;",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                              Text("总体积:",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                              Text("0方;",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                              Text("总重量:",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                              Text("0吨",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                            ],
                          ),
                          Icon(Icons.keyboard_arrow_up,color: MyColors.textColor,size: 20,),
                        ],
                      ),
                      onTap: (){
                        setState(() {
                          isShow=!isShow;
                        });
                      },
                    ),
                  if(isChooseList.isNotEmpty)
                    SizedBox(height: 15.h,),
                  BrnSmallMainButton(
                    title: '配载调度',
                    bgColor: MyColors.themeColor,
                    textColor: Colors.white,
                    fontSize: 14.sp,
                    radius: 30,
                    width: screenSize.width-30.w,
                    onTap: () {

                    },
                  ),
                ],
              )

            )
          ],
        ),

      ),
    );
  }
}
